import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import replace from '@rollup/plugin-replace'
import viteCompression from 'vite-plugin-compression';

export default defineConfig({
  plugins: [
    vue({
      template: {
        compilerOptions: {
          // 将所有标准 HTML 标签标记为原生元素
          isCustomElement: (tag) => ['p', 'div', 'span', 'a'].includes(tag),
        }
      }
    }),
    viteCompression({
      algorithm: 'gzip', // 或 'brotli'
      ext: '.gz', // 或 '.br'
      threshold: 10240, // 10KB 以上才压缩
    })
  ],
  resolve: {
    alias: {
      '@vue/compiler-dom': '@vue/compiler-dom/dist/compiler-dom.cjs.js',
      '@vue/compiler-core': '@vue/compiler-core/dist/compiler-core.cjs.js',
    },
  },
  base: './',
  build: {
    commonjsOptions: {
      ignore: ['typescript'],
    },
  },
  worker: {
    format: 'es',
    plugins: () => [
      replace({
        preventAssignment: true,
        values: {
          'process.env.NODE_ENV': JSON.stringify('production'),
        },
      }),
    ],
  },
})
